package echat.future.cn.echat.message.weekrank;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.message.MessageApi;
import echat.future.cn.echat.message.bean.RankListBean;
import echat.future.cn.echat.message.rank.RankActivity;
import echat.future.cn.echat.message.weekrank.adapter.RankListAdapter;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.utils.UserHelper;
import lumingweihua.future.cn.baselibgxh.base.BaseActivity;

/**
 * 活动列表
 * Created by JX on 2018/9/1.
 */

public class RankListActivity extends BaseActivity {

    private RecyclerView mRecyclerView;
    private RankListAdapter mAdapter;

    @Override
    protected void initView() {
        setContentView(R.layout.rank_list_activity);

        findViewById(R.id.iv_back).setOnClickListener(this);
        mRecyclerView = findViewById(R.id.rv);

        mAdapter = new RankListAdapter(R.layout.rank_list_rv_item, new ArrayList<>());
        mAdapter.bindToRecyclerView(mRecyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                startActivity(RankWeekActivity.getIntent(RankListActivity.this, mAdapter.getData().get(position).getId()));
            }
        });
    }

    @Override
    protected void initData() {

        new HttpUtilsRequst<List<RankListBean>>(this, HttpUtilsRequst.retrofitClient.create(MessageApi.class)
                .week_rank_list(1))
                .setmOnRequstSuccessListener(new HttpUtilsRequst.OnRequstSuccessListener<List<RankListBean>>() {
                    @Override
                    public void onSuccss(List<RankListBean> ebiBeans) {
                        mAdapter.setNewData(ebiBeans);
                    }
                })
                .setmOnRequstFaileListener(new HttpUtilsRequst.OnRequstFaileListener() {
                    @Override
                    public void onFaile(int code, String msg) {

                    }
                })
                .start();
    }

    @Override
    protected void processClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
